
import yaml
from common.a_env_PATH import pathConf

class YamlRead(object):
    def __init__(self,yamlPath):
        self.yamlPath = yamlPath
        with open(yamlPath, mode='r', encoding='utf8') as file_config:
            config_dict = yaml.load(file_config.read(), Loader=yaml.FullLoader)
            # print(config_dict)
        self.yamldata = config_dict

    def getdata(self):
        """ 返回一个字典 """
        # print(self.yamldata)
        return self.yamldata

    def write_data(self,data):
        """ 写入yaml """
        with open(self.yamlPath, "a+", encoding="utf-8") as f:
            # 注：此模式为追加模式,若想直接重写则将open函数中的模式'a+'改为'w'
            yaml.dump(data, f)
        f.close()


def openReade(file):
    """
    文件读取
    :param file 需要被读取的文件路径
    :return: data 返回文件全部内容
    """
    with open(file, mode='r') as f:
        data = f.read()  # 读取全部内容，返回字符串
    return data

if __name__ == '__main__':
    pass
    # a = YamlRead(pathConf.get_userFilePath("data/a_envData/env.yaml"))
    # print(a.getdata()['test_domain'].split(":")[0])
